cmake_minimum_required(VERSION 3.9)
project(EasyGIS)
set(CMAKE_CXX_STANDARD 11)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

# qt5相关设置
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

# 项目相关配置
set(HEADER_SOURCES include/mapcanvas.h
        include/mapcanvasmap.h
        include/maptool.h
        include/tools/maptoolpan.h
        include/tools/maptoolzoomin.h
        include/crs.h
        include/maplayer.h
        include/utils/network.h
        include/pointxy.h
        include/utils/easygis.h
        include/crs/webmercator.h
        include/provider/tmsprovider.h
        include/layer/tmslayer.h
        include/provider/tms/ostnormalprovider.h
        include/layerprovider.h
        include/gui/mainwindow.h
        include/provider/tms/gaodenormalprovider.h
        include/provider/tms/gaodesatelliteprovider.h
        include/provider/tms/googlechinanormalprovider.h
        include/provider/tms/googlechinasatelliteprovider.h
        include/gui/sponsorwindow.h
        include/provider/tms/tmsproviderfactory.h
        include/tools/maptoolzoomout.h
        include/tools/maptoolselect.h
        include/utils/imgwriter.h
        include/gui/taskwindow.h)

set(CPP_SOURCES egmain.cpp
        mapcanvas.cpp
        mapcanvasmap.cpp
        utils/network.cpp
        pointxy.cpp
        crs.cpp
        maplayer.cpp
        layer/tmslayer.cpp
        provider/tmsprovider.cpp
        provider/tms/ostnormalprovider.cpp
        crs/webmercator.cpp
        gui/mainwindow.cpp
        provider/tms/gaodenormalprovider.cpp
        maptool.cpp
        tools/maptoolpan.cpp
        gui/sponsorwindow.cpp
        provider/tms/tmsproviderfactory.cpp
        tools/maptoolzoomin.cpp
        tools/maptoolzoomout.cpp
        tools/maptoolselect.cpp
        utils/imgwriter.cpp
        gui/taskwindow.cpp)

# qt资源文件
set(RES_FILES resources/res.qrc)

include_directories(include)
add_executable(EasyGIS WIN32 ${HEADER_SOURCES} ${CPP_SOURCES} ${RES_FILES})

# 引入Qt5Widgets
find_package(Qt5Widgets CONFIG REQUIRED)
message("Qt5Widgets include directory=> ${Qt5Widgets_INCLUDE_DIRS}")
include_directories(${Qt5Widgets_INCLUDE_DIRS})
target_link_libraries(EasyGIS Qt5::Widgets)

# 引入Qt5Sql
find_package(Qt5Sql CONFIG REQUIRED)
message("Qt5Sql include directory=>${Qt5Sql_INCLUDE_DIRS}")
include_directories(${Qt5_INCLUDE_DIRS})
target_link_libraries(EasyGIS Qt5::Sql)

# 引入curl库
find_package(CURL REQUIRED)
if (WIN32)
    list(LENGTH CURL_LIBRARY CURL_LIBRARY_LENGTH)
    if (CURL_LIBRARY_LENGTH EQUAL 1)
      set(CURL_LIBRARY_DEBUG_LIB   ${CURL_LIBRARY})
       set(CURL_LIBRARY_RELEASE_LIB ${CURL_LIBRARY_DEBUG_LIB}/../../../lib/libcurl.lib)
        get_filename_component(CURL_LIBRARY_RELEASE_LIB ${CURL_LIBRARY_RELEASE_LIB} REALPATH)
        unset(CURL_LIBRARY CACHE)
        unset(CURL_LIBRARY)
        unset(CURL_LIBRARIES  CACHE)
        unset(CURL_LIBRARIES)
        set(CURL_LIBRARY "debug;${CURL_LIBRARY_DEBUG_LIB};optimized;${CURL_LIBRARY_RELEASE_LIB}")
        set(CURL_LIBRARIES ${CURL_LIBRARY})
    endif()
  endif()
message("curl include directory=>${CURL_INCLUDE_DIRS}")
include_directories(${CURL_INCLUDE_DIRS})
target_link_libraries(EasyGIS ${CURL_LIBRARIES})

# 引入proj4库
find_package(PROJ4 CONFIG REQUIRED)
message("proj4 include directory=>${PROJ4_INCLUDE_DIRS}")
include_directories(${PROJ4_INCLUDE_DIRS})
target_link_libraries(EasyGIS ${PROJ4_LIBRARIES})